PageProps Type Errors in Next.js #142577
-
Select Topic AreaBug BodyHello everyone, However, during the build process, I encounter the following TypeScript error: Could you advise on how to correctly resolve these type issues or effectively suppress this error? I've attempted to use the comment // @ts-expect-error: params type does not match expected PageProps, but the error persists. Thank you for your assistance! |
Beta Was this translation helpful? Give feedback.
Replies: 21 comments 40 replies
-
💬 Your Product Feedback Has Been Submitted 🎉 Thank you for taking the time to share your insights with us! Your feedback is invaluable as we build a better GitHub experience for all our users. Here's what you can expect moving forward ⏩
Where to look to see what's shipping 👀
What you can do in the meantime 💻
As a member of the GitHub community, your participation is essential. While we can't promise that every suggestion will be implemented, we want to emphasize that your feedback is instrumental in guiding our decisions and priorities. Thank you once again for your contribution to making GitHub even better! We're grateful for your ongoing support and collaboration in shaping the future of our platform. ⭐ |
Beta Was this translation helpful? Give feedback.
-
error happens because TypeScript thinks params should be a Promise, not a plain object. export default async function Page({ params }: { params: { slug: string[] } } as any) { |
Beta Was this translation helpful? Give feedback.
-
Hi @Universe0809, To address these changes, you have a couple of options:
export default async function Page({ params }: { params: Params }) { This approach ensures that your application remains compatible with the latest version of Next.js. Thank you for taking my suggestion into account. |
Beta Was this translation helpful? Give feedback.
-
Here’s how I fix this issse:import Link from "next/link";
import photos, { Photo } from "@/lib/";
import PhotoCard from "@/components/photo-card";
export const generateStaticParams = () => {
return photos.map(({ id }) => ({
id: String(id),
}));
};
export type paramsType = Promise<{ id: string }>;
export default async function PhotoPage(props: { params: paramsType }) {
const { id } = await props.params;
const photo: Photo | undefined = photos.find((p) => p.id === id);
if (!photo) {
return <div>Photo not found</div>;
}
return (
<section className="py-24">
<div className="container">
<div>
<Link
href="/photos"
className="font-semibold italic text-sky-600 underline"
>
Back to photos
</Link>
</div>
<div className="mt-10 w-1/3">
<PhotoCard photo={photo} />
</div>
</div>
</section>
);
} |
Beta Was this translation helpful? Give feedback.
-
If you’ve encountered the same issue I did, it was due to having a monorepo with multiple React dependencies. Specifically, one of my packages was still using React 18, which caused a type mismatch. |
Beta Was this translation helpful? Give feedback.
-
I had the same issue but it was more than one file that needed to be changed. So if anyone encounters the same issue just run this command in the terminal. It will fix all the files for you. |
Beta Was this translation helpful? Give feedback.
-
Is next turning into a |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
if someone have a client page with hooks or some other client side stuff you can split the components in two with a server component passing params to the client component. import { ClientPage } from "./client-page";
export type paramsType = Promise<{ id: string }>;
type Props = {
params: paramsType;
};
const Page = async ({ params }: Props) => {
const { id } = await params;
return <ClientPage id={id} />;
};
export default Page; "use client";
import { HeaderActions } from "./_components/header-actions";
import { EnvSelector } from "./_components/env-selector";
import { PromptEditor } from "./_components/prompt-editor";
import { SettingsPanel } from "./_components/settings-panel";
import { Playground } from "./_components/playground";
import { ShadowWrapper } from "@/app/(authenticated)/components/shadow-wrapper";
import { useGetCircut } from "@repo/features/circut";
type Props = {
id: string;
};
export const ClientPage = ({ id }: Props) => {
const { data, isLoading, isPending } = useGetCircut(id);
return (
<div className="flex min-h-screen">
<ShadowWrapper>
<div className="flex-1">
<HeaderActions />
<EnvSelector />
<div className="container mx-auto max-w-7xl">
<div className="grid grid-cols-3 gap-8 p-8">
<div className="col-span-2">
<PromptEditor />
<Playground />
</div>
<div className="col-span-1">
<SettingsPanel />
</div>
</div>
</div>
</div>
</ShadowWrapper>
</div>
);
}; |
Beta Was this translation helpful? Give feedback.
-
I was able to solve the issue with codemods: |
Beta Was this translation helpful? Give feedback.
-
Your a fuckin genius I love you
…On Mon, Jan 27, 2025, 1:47 PM Stan4394 ***@***.***> wrote:
I was able to solve the issue with codemods: npx @***@***.***
next-async-request-api .
—
Reply to this email directly, view it on GitHub
<#142577 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BNILBZAX3ER5P2K55AX7EQ32MZ5LHAVCNFSM6AAAAABQSZS72CVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCOJXGM4DSNI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
I wont go when we use useState in the same file. we cant use useState along with async func.. should i consider removing all the useStates?? |
Beta Was this translation helpful? Give feedback.
-
import React from 'react'; export type paramsType = Promise<{ id: string }>; type Props = { const Page = async ({ params }: Props) => { {id}); }; export default Page; It works |
Beta Was this translation helpful? Give feedback.
-
hey any one help how can i resolve this error src/app/blogs/[id]/page.tsx here is code import { onGetCurrentDomainInfo } from '@/actions/settings'; // Proper typing for dynamic route parameters export default async function DomainSettingsPage({ params }: PageParams) { if (!domainInfo) { const domain = domainInfo.domains?.[0] || {}; return ( <SettingsForm plan={domainInfo.subscription?.plan || ''} chatBot={domain.chatBot || null} id={domain.id || ''} name={domain.name || ''} /> {domain.id && } {domain.id && <ProductTable id={domain.id} products={domain.products || []} />} </> ); } |
Beta Was this translation helpful? Give feedback.
-
GENIUS AND A LIFE SAVER |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I haven't yet found a solution. On Apr 24, 2025 10:04 AM, Sathya ***@***.***> wrote:
@danielgrahamboaz I was also facing the same issue. I’ve tried multiple ways, but it’s still not resolved. Did you find any other solution?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
SureOn Apr 24, 2025 10:54 AM, Sathya ***@***.***> wrote:
Let me know if you find a solution; if I find one, I'll let you know
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Yeah me too On Apr 24, 2025 11:39 AM, Sathya ***@***.***> wrote:
I'm still facing the same error.
Error: Route "/blog/[slug]" used params.slug. params should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at Page (c:\Users\softsuave-pc\Desktop\nextjs-contentful\src\app\blog[slug]\page.tsx:46:10)
44 |
45 | export default async function Page({ params }: { params: Params }) {
46 | const { slug } = params;
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Did it work?On Apr 24, 2025 11:57 AM, Sathya ***@***.***> wrote:
I have tried it this way too:
image.png (view on web)
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
update your page component to work with ### Next.js 15, which expects [params] to be a Promise that needs to be awaited. here is the demo import { notFound } from "next/navigation"; interface PageParams { export type ParamsType = Promise; export async function generateMetadata({ export default async function SubdomainPage({ try {
} catch (error) { Error
); } } |
Beta Was this translation helpful? Give feedback.
Hi @Universe0809,
It appears that there are breaking changes in Next.js version 15 related to properties such as params. The official documentation highlights this issue (see: Next.js v15 Upgrade Guide).
To address these changes, you have a couple of options:
`type Params = Promise<{ slug: string[] }>;
export default async function Page({ params }: { params: Params }) {
const { slug } = await params;
}`
This approach ensures that your application remains compatible with the latest version of Ne…